1. Technical Field
The present invention is generally directed to an improved mechanism for optimizing computer code. More specifically, the present invention is directed to a system and method for reorganizing portions of source code based on frequency based loop replication in order to facilitate optimizations during recompilation of computer source code.
2. Description of Related Art
In source code, instruction loops that have conditional logic in them, with a subset of the conditions dominating the execution path, are commonly found. For example, parser code, e.g., Extensible Markup Language (XML) parsers and compiler parsers, often includes such instruction loops. Much work has been performed with regard to optimizing such instructions loops.
Known proposed solutions today are to re-write sections of code in assembler language or to use a co-processor to manage a finite state machine representing the various states of the instruction loop(s). Rewriting code in assembler language is typically not done because of the enormous cost to the development team to develop and maintain this code. Co-processors typically require too much startup time and thus, provide a lesser overall benefit if the instructions being looped over is short.
Since such instructions loops include both blocks of code that are often executed and blocks of code that are rarely executed, optimizing the source code as is results in a less than optimum solution. That is, the same optimizations are applied to both the frequently executed blocks of code in the instruction loop and the blocks of code that are rarely executed. As a result, the “optimized” blocks of code that are often executed may not be fully optimized due to the optimizations performed on the rarely executed blocks of code. Similarly, optimizations are performed on rarely executed blocks of code which may not need to be optimized since they do not appreciably affect performance of the code.
Thus, it would be beneficial to have an improved system and method for optimizing instructions loops that have conditional logic in them, with a subset of the conditions dominating the execution path.